// pages/empty/empty.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shi_k:true,
    xuan: [{
        xian: '已报名',
        zhuang: 1
      },
      {
        xian: '已激活',
        zhuang: 2
      },
    ],
    xian:'',

    BAL:'',
    BALaa:'',

    page: Number, // 起始页码
    totalPage: Number, //最大页码数
    videlist: '',
    value: '',
  },


  jinsou(){

if (this.data.BAL == '' && this.data.BALaa == '' ) {
  
  wx.showModal({
    title: "提示",
    content:'至少输入一个金额',
    showCancel: false,
  });
}else{



  this.getvidelist()
}



  },
  



  xuanzhuang(){
    this.setData({
      shi_k: false,
    })
  },

  buttn_c(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.zhuang);
 
    this.setData({
      xian: e.currentTarget.dataset.item.xian,
      zhuang: e.currentTarget.dataset.item.zhuang,
      shi_k: true,
    })
    this.getvidelist()
  },



  handleInput(e) {

    console.log(e);
    let value = this.validateNumber(e.detail.value)

    console.log(value);
    this.setData({
      BAL: value
    })
  },



  handleInputaa(e) {

    console.log(e);
    let value = this.validateNumber(e.detail.value)

    console.log(value);
    this.setData({
      BALaa: value
    })
  },




  validateNumber(val) {
    return val.replace(/\D/g, '')
  },



  onchange(event) {
    console.log(event);
    const value = event.detail
    console.log(value);
    this.setData({
      value: value
    })
  },

  getvidelist(n = '') {
    this.setData({
      EMPLOYEE_ID: app.globalData.mealsList,
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
    })
    wx.showLoading({
      title: '加载中...',
    })

    wx.request({
      url: app.globalData.interface+'/crossVersionOne/API2_2211_SelectXuKeXuJinList',
      method: 'POST',
      data: {
        OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
        currentPage: "", //当前页   非必填
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,
        EMPLOYEE_ID: this.data.EMPLOYEE_ID,
        keyWord: this.data.value,
        VALID:2,
        BALMAX: this.data.BALaa,
        BALMIN: this.data.BAL,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log('res', res);
        console.log('res', res.data.result);
        wx.hideLoading()
        if (res.data.result == 'success' && res.data.data.length != 0) {
          console.log('翻页', res.data.data[0].page.totalPage);

          const copypage = JSON.stringify(res.data.data[0].page.totalPage)
          const totalPage = JSON.parse(copypage)
          console.log('totalPage', totalPage);
          this.setData({
            videlist: res.data.data,
            totalPage: totalPage
          })

          console.log('最大页码数', this.data.totalPage);

        } else {
          wx.showModal({
            title: "提示",
            content: res.data.data,
            showCancel: false,
          });
        }
      },
      fail: (res => {
        wx.hideLoading()
      })
    })


  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      EMPLOYEE_ID: e.data,
      EMPLOYEE_ID: app.globalData.mealsList,
      openid: app.globalData.openid,

      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,


    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {


    this.setData({
      page: 1, // 起始页码
    })

    this.getvidelist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {



  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})